home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
telecomm
/
uemlsrc.arc
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-08-24
|
23KB
|
645 lines
/*
* This program is in public domain; written by Dave G. Conroy.
* This file contains the main driving routine for the Micro-
* EMACS screen editor. This version began as the original
* small version by DGC. It has been extensively expanded
* using versions 35 (a hybrid) and 36 (a direct descendent).
* This version includes a number of text functions that are
* not found in others and a word wrap algorithm different from
* 35 or 36. It also contains a kermit module, real page movement,
* printer support and a shell command. It is sort of a cross
* between ME and Perfect Writer version 1.03.
*/
#include <stdio.h>
#include <ctype.h>
#include <osbind.h>
#include "ed.h"
#if ST
#include "keycode.h"
#endif
#if VMS
#include <ssdef.h>
#define GOOD (SS$_NORMAL)
#endif
#ifndef GOOD
#define GOOD 0
#endif
char *version = "v. 33 25-January-1987";
int currow; /* Working cursor row */
int curcol; /* Working cursor column */
int fillcol = 76; /* Current fill column */
int indcol; /* Current indent column */
int thisflag; /* Flags, this command */
int lastflag; /* Flags, last command */
int curgoal; /* Goal column */
int isnprint; /* Print buffer in use */
int glmode = BMNWRAP; /* Begin in fundamental mode */
BUFFER *curbp; /* Current buffer */
WINDOW *curwp; /* Current window */
BUFFER *bheadp; /* BUFFER listhead */
WINDOW *wheadp; /* WINDOW listhead */
BUFFER *blistp = NULL; /* Buffer list BUFFER */
BUFFER *bmacrp = NULL; /* Compiled macros BUFFER */
short kbdm[NKBDM] = CTLX|')'; /* Macro */
short *kbdmip; /* Input for above */
short *kbdmop; /* Output for above */
char pat[NPAT]; /* Pattern */
char rpat[NPAT]; /* Replacement pattern */
char prnhdr[NPAT]; /* Print header */
char prndate[NPAT]; /* Print date */
char lastbuf[NBUFN]; /* Last buffer name */
char defpath[128]; /* default path name */
int defdrive; /* default drive */
long buserr; /* Address of gemdos busserr */
long adderr; /* Address of gemdos address err*/
long progend; /* end of program after init */
main(argc, argv)
int argc;
char *argv[];
{
register int c;
register int f;
register int n;
register int mflag;
register int prncnt;
register int basec;
extern int errexit();
extern long sbrk();
#if ALCYON
fclose(stdin); /* reduce overhead for */
fclose(stdout); /* unused file pointers */
fclose(stderr);
#endif
isnprint = FALSE;
prncnt = 0;
if (access("cc.ini",4) == NULL) /* cc drive assignments */
commfil(FALSE,HUGE); /* and function key bind*/
strcpy(lastbuf, "main"); /* Work out the name of */
if (argc > 1) /* the default buffer. */
makename(lastbuf, argv[1]);
edinit(lastbuf); /* Buffers, windows. */
vtinit(); /* Displays. */
update();
#if ST
defdrive = Dgetdrv();
Dgetpath(defpath,0);
buserr = Setexc(2,-1L);
adderr = Setexc(3,-1L);
Setexc(2,&errexit); /* Clean up screen on err */
Setexc(3,&errexit);
#endif
if (access("uemail.mcr",4) == NULL) /* default macro file */
{
update();
loadmac(FALSE);
}
progend = sbrk(0);
if (argc > 1) {
update(); /* You have to update */
readin(argv[1]); /* in case "[New file]" */
}
lastflag = 0; /* Fake last flags. */
loop:
update(); /* Fix up the screen */
/* This is the print buffer code. It's very rudimentary, but it
* works as long as the buffer in the printer does not get filled.
* On the initial call to the function print(), the printer is
* sent one 1536 byte buffer of data and isnprint is set to
* TRUE. From then on the printer is sent 384 bytes of data after
* an arbitrary number of keystrokes is entered if the printer
* is ready.
*/
if(isnprint) /* We are printing a file */
if (prncnt++ > 16) /* Keystroke count */
if(PRNRDY) /* Check LST: status */
{
prnbuf(); /* Send a buffer full */
prncnt = 0;
}
f = getkey();
if (shiftstatus == 17 || shiftstatus == 18) /* CapsLock + Shift */
c = tolower(f);
else
c = f;
if (mpresf != FALSE) {
mlerase();
update();
}
f = FALSE;
n = 1;
/* do META-# processing if needed */
basec = c & ~META; /* strip meta char off if there */
if ((c & META) && ((basec >= '0' && basec <= '9') || basec == '-')) {
f = TRUE; /* there is a # arg */
n = 0; /* start with a zero default */
mflag = 1; /* current minus flag */
c = basec; /* strip the META */
while ((c >= '0' && c <= '9') || (c == '-')) {
if (c == '-') {
/* already hit a minus or digit? */
if ((mflag == -1) || (n != 0))
break;
mflag = -1;
} else {
n = n * 10 + (c - '0');
}
if ((n == 0) && (mflag == -1)) /* lonely - */
mlwrite("Arg:");
else
mlwrite("Arg: %d",n * mflag);
c = getkey(); /* get the next key */
}
n = n * mflag; /* figure in the sign */
}
/* ^U expansion */
if (c == (CTRL|'U')) { /* ^U, start argument */
f = TRUE;
n = 4; /* with argument of 4 */
mflag = 0; /* that can be discarded. */
mlwrite("Arg: 4");
while ((c=getkey()) >='0' && c<='9' || c==(CTRL|'U') || c=='-'){
if (c == (CTRL|'U'))
n = n*4;
/*
* If dash, and start of argument string, set arg.
* to -1. Otherwise, insert it.
*/
else if (c == '-') {
if (mflag)
break;
n = 0;
mflag = -1;